package com.muyu.danmo.controller;


import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.PageUtils;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoGalleryWorkBids;
import com.muyu.danmo.service.IDanmoGalleryWorkBidsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 画廊出价Controller
 *
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/galleryWorkBids")
public class DanmoGalleryWorkBidsController extends BaseController
{
    @Autowired
    private IDanmoGalleryWorkBidsService danmoGalleryWorkBidsService;

    /**
     * 查询画廊出价列表
     */
//    @RequiresPermissions("system:galleryWorkBids:list")
    @PostMapping("/list")
    public Result<PageInfo<DanmoGalleryWorkBids>> list(@RequestBody  DanmoGalleryWorkBids danmoGalleryWorkBids)
    {
        PageUtils.startPage(danmoGalleryWorkBids.getPageNum(), danmoGalleryWorkBids.getPageSize());
        List<DanmoGalleryWorkBids> list = danmoGalleryWorkBidsService.selectDanmoGalleryWorkBidsList(danmoGalleryWorkBids);
        PageInfo<DanmoGalleryWorkBids> danmoGalleryWorkBidsPageInfo = new PageInfo<>(list);
        return Result.success(danmoGalleryWorkBidsPageInfo);
    }

    /**
     * 导出画廊出价列表
     */
//    @RequiresPermissions("system:galleryWorkBids:export")
    @Log(title = "画廊出价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoGalleryWorkBids danmoGalleryWorkBids)
    {
        List<DanmoGalleryWorkBids> list = danmoGalleryWorkBidsService.selectDanmoGalleryWorkBidsList(danmoGalleryWorkBids);
        ExcelUtil<DanmoGalleryWorkBids> util = new ExcelUtil<DanmoGalleryWorkBids>(DanmoGalleryWorkBids.class);
        util.exportExcel(response, list, "画廊出价数据");
    }

    /**
     * 获取画廊出价详细信息
     */
//    @RequiresPermissions("system:galleryWorkBids:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoGalleryWorkBidsService.selectDanmoGalleryWorkBidsById(id));
    }

    /**
     * 新增画廊出价
     */
//    @RequiresPermissions("system:galleryWorkBids:add")
    @Log(title = "画廊出价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody DanmoGalleryWorkBids danmoGalleryWorkBids)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser==null){
            return Result.notLoggedIn("请登录");
        }
        danmoGalleryWorkBids.setUserId(loginUser.getUserid());
        return Result.success(danmoGalleryWorkBidsService.insertDanmoGalleryWorkBids(danmoGalleryWorkBids));
    }

    /**
     * 修改画廊出价
     */
//    @RequiresPermissions("system:galleryWorkBids:edit")
    @Log(title = "画廊出价", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoGalleryWorkBids danmoGalleryWorkBids)
    {
        return toAjax(danmoGalleryWorkBidsService.updateDanmoGalleryWorkBids(danmoGalleryWorkBids));
    }

    /**
     * 删除画廊出价
     */
//    @RequiresPermissions("system:galleryWorkBids:remove")
    @Log(title = "画廊出价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoGalleryWorkBidsService.deleteDanmoGalleryWorkBidsByIds(ids));
    }



}
